package com.daniel.juc.add;

import java.util.concurrent.CountDownLatch;

/**
 * 详细说明
 *
 * @author Daniel
 * @version V1.0
 * @date 2020/5/20 11:11
 */
public class CountDownLatchDemo {
	public static void main(String[] args) {
		// 总数是6，必须要执行任务的时候，在使用
		CountDownLatch countDownLatch = new CountDownLatch(6);

		for (int i = 1; i <= 6; i++) {
			new Thread(() -> {
				System.out.println(Thread.currentThread().getName() + " Go out");
				// 数量-1
				countDownLatch.countDown();
			}, String.valueOf(i)).start();
		}

		// 等待计数器归零，然后向下执行
		try {
			countDownLatch.await();
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println("Close door");
	}
}
